feat(ai): auto-strip <think> reasoning tags in OpenAI adapter#47
Merged
Conversation
Models like DeepSeek emit <think>...</think> blocks containing chain-of-thought reasoning. This commit strips those tags from response text and exposes the reasoning content separately: - Add stripThinkTags() utility for non-streaming responses - Add optional `reasoning` field to ModelResponse type - Add ReasoningDelta stream event type for streaming responses - Handle edge cases: multiple blocks, unclosed tags, case-insensitive - 20 new unit tests covering utility, generate, and stream paths Closes #45
There was a problem hiding this comment.
🤖 AI Code Review
Automated review for PR #47 — informational only, does not block merge.
Checklist
| Item | Notes | |
|---|---|---|
| Type Safety | 2 use(s) of any detected |
|
| Error Handling | async code added without visible error handling | |
| ✅ | Test Coverage | 1 test file(s) updated |
| API Consistency | 4 new export(s) added; 1 export(s) removed — potential breaking change | |
| Breaking Changes | Public exports removed; check downstream consumers |
Stats
- 📁 Files changed: 5 (5 TypeScript)
- ➕ Lines added: 535
- 🧪 Test files updated: 1
4 check(s) need attention.
Powered by openlinkos/agent · AI PR Review workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stripThinkTags()utility to strip<think>...</think>reasoning blocks from model output (handles multiple blocks, unclosed tags, case-insensitive matching)OpenAIAdapter.doGenerate()— strips think tags fromresponse.textand extracts reasoning into optionalresponse.reasoningfieldReasoningDeltastream event type and integrate intoparseSSEStream()— think content is emitted asreasoning_deltaevents instead oftext_deltareasoningfield toModelResponsetypestripThinkTags,StripThinkTagsResult, andReasoningDeltafrom package indexTest plan
stripThinkTags()utility (single block, multiple blocks, unclosed tag, case-insensitive, multiline, empty, whitespace-only, etc.)doGenerate()(strips tags, no tags, null content, all-reasoning content, generateWithTools)pnpm test— all 1018 tests pass (70 files, 0 failures)pnpm --filter @openlinkos/ai typecheck— passesCloses #45